package com.cy.sort;


import java.sql.SQLOutput;

/**
 * @Author: chenyun
 * @Date: 2021/09/13/21:35
 * @Description:
 */

// 冒泡排序
public class BubbleSort {
    public static void bubbleSort(int[] arry){
        for (int i = 0; i < arry.length-1; i++) {
            for (int j = 0; j < arry.length-i-1; j++) {
                // 比较相邻两个树  如果后面的比前面的小就交换位置
                if(arry[j+1]<arry[j]){
                    int tem = arry[j+1];
                    arry[j+1] = arry[j];
                    arry[j] = tem;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] arry = {9,1,5,8,3};
        bubbleSort(arry);
        for (int a : arry) {
            System.out.print(a+" ");
        }
    }
}
